package com.wangwei.sort;

import edu.princeton.cs.algs4.StdOut;

/**
 * 选择排序
 */
public class Selection extends Example{

    public  void sort(Comparable[] arr){
        int N = arr.length;
        for(int i=0;i<N;i++){
            int min =i;
            for(int j = i+1; j<N; j++){
                if(less(arr[j],arr[min])) min = j;
            exch(arr,i,min);
            }
        }
    }
    public static void main(String[] args) {
        String [] arr = {"A","S","D","F","G","H","J","K","L"};
        Example example = new Selection();

        example.sort(arr);
        assert example.isSorted(arr);
        example.show(arr);
    }


}
